package com.example.cromos;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	
	private Button addBt;
	private Button removeBt;
	private EditText cromoTx;
	private EditText cromoQuantityTx;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		 addBt = (Button) findViewById(R.id.addBt);
		 removeBt = (Button) findViewById(R.id.removeBt);
		 cromoTx = (EditText) findViewById(R.id.cromoTx);
		 cromoQuantityTx = (EditText) findViewById(R.id.quantityEditText);
		 
		 addBt.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				String cromoValue = cromoTx.getText().toString();
				String cromoQuantityString = cromoQuantityTx.getText().toString();
				
				
				int cromoQuantity = Integer.parseInt(cromoQuantityString);
				Cromo cromo = new Cromo(cromoValue, cromoQuantity);
				CromoDAO.addCromo(cromo);
				cromo = CromoDAO.getCromo(cromo.getName());
				String text = "Id: " + cromo.getName() + "\nQuantity: " + cromo.getQuantity();
				Toast.makeText(getApplicationContext(), text, 10000).show();
				
				
				//Intent intent = new Intent(getApplicationContext(), SecActivity.class);
				//startActivity(intent);
			}
		 });
			
			
			
			removeBt.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					String cromoValue = cromoTx.getText().toString();
					String cromoQuantityString = cromoQuantityTx.getText().toString();
					
					
					int cromoQuantity = Integer.parseInt(cromoQuantityString);
					Cromo cromo = new Cromo(cromoValue, cromoQuantity);
					CromoDAO.removeCromo(cromo);
					cromo = CromoDAO.getCromo(cromo.getName());
					String text = "Id: " + cromo.getName() + "\nQuantity: " + cromo.getQuantity();
					Toast.makeText(getApplicationContext(), text, 10000).show();
					
					
					//Intent intent = new Intent(getApplicationContext(), SecActivity.class);
					//startActivity(intent);
				}
			});
				
			
			
			
			
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
